import { DesignPattern } from '@/types';
import { creationalPatterns } from './patterns/creational';
import { structuralPatterns } from './patterns/structural';
import { behavioralPatterns } from './patterns/behavioral';

// 合并所有设计模式
export const patternsData: DesignPattern[] = [
  ...creationalPatterns,
  ...structuralPatterns,
  ...behavioralPatterns
];

export const getPatternById = (id: string): DesignPattern | undefined => {
  return patternsData.find(pattern => pattern.id === id);
};

// 按分类获取模式
export const getPatternsByCategory = (category: 'creational' | 'structural' | 'behavioral'): DesignPattern[] => {
  return patternsData.filter(pattern => pattern.category === category);
};

// 获取模式统计信息
export const getPatternsStats = () => {
  const stats = {
    total: patternsData.length,
    creational: creationalPatterns.length,
    structural: structuralPatterns.length,
    behavioral: behavioralPatterns.length
  };
  
  return stats;
};

// 按难度获取模式
export const getPatternsByDifficulty = (difficulty: '简单' | '中等' | '困难'): DesignPattern[] => {
  return patternsData.filter(pattern => pattern.difficulty === difficulty);
};

// 搜索模式
export const searchPatterns = (query: string): DesignPattern[] => {
  const lowercaseQuery = query.toLowerCase();
  return patternsData.filter(pattern => 
    pattern.name.toLowerCase().includes(lowercaseQuery) ||
    pattern.description.toLowerCase().includes(lowercaseQuery) ||
    pattern.useCases.some(useCase => useCase.toLowerCase().includes(lowercaseQuery))
  );
};
